package com.wen.task.customTask;

import com.wen.entry.Result;
import com.wen.entry.bean.WeaponAndSkill;
import com.wen.moudle.Account;
import com.wen.moudle.Managers.InformationManager;
import com.wen.task.AbstractTask;
import lombok.extern.slf4j.Slf4j;

import java.util.List;
import java.util.Scanner;

// 升级技能，慎用，成功率比较低
@Slf4j
public class LevelUpSkillTask extends AbstractTask {
    InformationManager informationManager = getInformationManager();
    public LevelUpSkillTask(Account account) {
        super(account);
    }

    @Override
    public String getTitle() {
        return "一键升级技能";
    }

    @Override
    public void run() {
        List<WeaponAndSkill> skill = informationManager.getSkill();
        skill.addAll(informationManager.getWeapon());
        Scanner in = new Scanner(System.in);
        for (int i = 0; i < skill.size(); i++) {
            System.out.println(String.format("%d. 【lv.%d】%s", i, skill.get(i).getLevel(), skill.get(i).getName()));
        }
        System.out.println("请输入要升级的武技...");
        int index = Integer.parseInt(in.nextLine());
        WeaponAndSkill skill1 = skill.get(index);

        while (true){
            Result<String> result = informationManager.levelUp(skill1);
            if (result.isSuccess() && result.getData() != null && result.getData().equals("true")){
                log.info("【{}】升级成功",skill1.getName());
            }else{
                if (result.getErrorMessage() == null || result.getErrorMessage().length() == 0){
                    log.info("【{}】升级失败",skill1.getName());
                }else{
                    log.info("{}",result.getErrorMessage());
                    log.info("退出升级任务");
                    break;
                }
            }
        }
    }
}
